#ifndef __FLASH_UID_H
#define __FLASH_UID_H

#include "stm32f10x.h"
#include "flash_write_read.h"

/* 宏定义 */
#define FLASH_OFFSET 16
#define UID_PAGE_MAX_NUM 250
#define KEY_BYTE_SIZE 6
#define FLASH_PAGE_SIZE 0x400
#define RFID_KEY_FLASH_SIZE 0x0C00
#define UID_KEY_BASE_ADDRESS 0x0800F000
#define RFID_FLASH_UID_NUM1_ADDRESS (UID_KEY_BASE_ADDRESS)
#define RFID_FLASH_UID_NUM2_ADDRESS (UID_KEY_BASE_ADDRESS + 1)
#define RFID_FLASH_UID_NUM3_ADDRESS (UID_KEY_BASE_ADDRESS + 2)
#define RFID_FLASH_UID_NUM4_ADDRESS (UID_KEY_BASE_ADDRESS + 3)
#define KEY_ADMIN_FLASH_ADDRESS (UID_KEY_BASE_ADDRESS + 4)
#define KEY_USER_FLASH_ADDRESS (UID_KEY_BASE_ADDRESS + 10)
#define UID_START_ADDRESS (UID_KEY_BASE_ADDRESS + 16)


//存放wifi数据
#define WIFINAME_ADDRESS_SIZE 0x0800FC00  // 存储name字节数
#define WIFINAME_ADDRESS (WIFINAME_ADDRESS_SIZE+2)  // 存储name
#define WIFIPASSWORD_ADDRESS_SIZE (WIFINAME_ADDRESS_SIZE + 34)  // 存储password字节数
#define WIFIPASSWORD_ADDRESS (WIFINAME_ADDRESS+34)  // 存储password


#define BUFFER_ADDRESS 0x0800EC00 


/* 结构体 共同体*/
typedef union
{
	uint32_t uids;
	uint8_t uid[4];
}uid_flash_buf;



/* 函数定义 */

void flash_uid_init(void);
void key_uid_init(void);
uint8_t uid_flash_exist(uint8_t *uid,uint8_t *page_num,uint8_t *uid_flash_num);
uint8_t comparison_uid(uint8_t *uid1,uint8_t *uid2);
uint8_t add_uid(uint8_t *uid);
uint8_t sub_uid(uint8_t page_num,uint8_t uid_flash_num);

uint8_t storage_wifi_name(uint8_t *name,uint8_t len);
uint8_t storage_wifi_password(uint8_t *password,uint8_t len);
#endif
